<template>
  <div class="app-container">
    <div style=" float: left;width: 100%">
      <div>
        <el-descriptions column="4" class="my-descriptions" style="margin-bottom: 30px; margin-left: 10.5px;font-size: 16px;">
          <el-descriptions-item label="负责人">{{form.firstName}}</el-descriptions-item>
          <el-descriptions-item label="负责人学院"><dict-tag :options="dict.type.cxcy_college" :value="form.firstCollege"/></el-descriptions-item>
        </el-descriptions>
      </div>
  <el-table
    :data="tableData"
    stripe
    style="width: 100%">
    <el-table-column label="成果名称" align="center" prop="resultName" />
    <el-table-column label="完成单位" align="center" prop="completionUnit" />
    <el-table-column label="成果类型" align="center" prop="resultType" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.cxcy_result_type" :value="scope.row.resultType"/>
      </template>
    </el-table-column>
    <!--<el-table-column label="成果简介" align="center" prop="resultIntroduction" />
    <el-table-column label="创新点" align="center" prop="innovationPoint" />
    <el-table-column label="参赛经历" align="center" prop="competitionExperience" />
    <el-table-column label="成果图片1的路径" align="center" prop="picturePath1" />
    <el-table-column label="成果图片2的路径" align="center" prop="picturePath2" />-->
    <el-table-column label="成果类别" align="center" prop="resultCategory" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.cxcy_result_category" :value="scope.row.resultCategory"/>
      </template>
    </el-table-column>
    <el-table-column label="成果等级" align="center" prop="resultGrade" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.cxcy_result_grade" :value="scope.row.resultGrade"/>
      </template>
    </el-table-column>
    <el-table-column label="成果来源" align="center" prop="resultSource" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.cxcy_result_source" :value="form.resultSource"/>
      </template>
    </el-table-column>
    <el-table-column label="成果背景" align="center" prop="resultBackground" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.cxcy_result_background" :value="form.resultBackground"/>
      </template>
    </el-table-column>
    <el-table-column label="技术领域" align="center" prop="technology" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.cxcy_technology" :value="scope.row.technology"/>
      </template>
    </el-table-column>
    <el-table-column label="立项时间" align="center" prop="projectTime" width="180">
      <template slot-scope="scope">
        <span>{{ parseTime(scope.row.projectTime, '{y}-{m}-{d}') }}</span>
      </template>
    </el-table-column>
  </el-table>
    </div>
    <div>
  <!--<el-table
    :data="tableData2"
    stripe
    style="width: 100%">
    <el-table-column
      align="center"
      prop="resultName"
      label="项目"
      width="526">
    </el-table-column>
    <el-table-column
      align="center"
      prop="level"
      label="等级"
      width="130">
    </el-table-column>
    <el-table-column
      align="center"
      prop="jiangli"
      label="奖项"
      width="130">
    </el-table-column>
    <el-table-column
      align="center"
      prop="date"
      label="日期"
      width="130">
    </el-table-column>
    <el-table-column
      align="center"
      prop="weizhi"
      label="未知"
      width="130">
    </el-table-column>
  </el-table>-->
    </div>
  </div>
</template>

<script>
  import {  getView,listAchievement2} from "@/api/module/cjl/achievement";
export default {
  dicts: ['cxcy_result_category','cxcy_result_type','cxcy_result_grade','cxcy_result_source','cxcy_technology','cxcy_isno','cxcy_cooperative_object','cxcy_result_year','cxcy_result_background','cxcy_college','cxcy_major','cxcy_signing_status'],
  data() {
    return {
      tableData: [],
      tableData2: [{
        project: '第二届"第嘉杯"辽宁省大学生中华优秀传统文化创新设计大赛',
        level:'省级',
        jiangli:'一等奖(银奖)',
        date: '2016-05-04',
        weizhi:'1',
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 分析报告表格数据
      analysisList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        resultName: null,
        resultType: null,
        resultIntroduction: null,
        innovationPoint: null,
        competitionExperience: null,
        picturePath1: null,
        picturePath2: null,
        resultCategory: null,
        resultGrade: null,
        resultSource: null,
        resultBackground: null,
        resultMeaning: null,
        projectTime: null,
        technology: null,
        completionUnit: null,
        applyName: null,
        applyNumber: null,
        applyTime: null,
        auditState: null,
        auditTime: null,
        auditName: null,
        auditNumber: null,
        isShow: null,
        firstName: null,
        firstGrade: null,
        firstMajor: null,
        firstNumber: null,
        firstCollege: null,
        firstPhone: null,
        firstIdnumber: null,
        secondName: null,
        secondGrade: null,
        secondMajor: null,
        secondNumber: null,
        secondCollege: null,
        secondPhone: null,
        secondIdnumber: null,
        thirdName: null,
        thirdGrade: null,
        thirdMajor: null,
        thirdNumber: null,
        thirdCollege: null,
        thirdPhone: null,
        thirdIdnumber: null,
        fourthName: null,
        fourthGrade: null,
        fourthMajor: null,
        fourthNumber: null,
        fourthCollege: null,
        fourthPhone: null,
        fourthIdnumber: null,
        fifthName: null,
        fifthGrade: null,
        fifthMajor: null,
        fifthNumber: null,
        fifthCollege: null,
        fifthPhone: null,
        fifthIdnumber: null,
        advisorName1: null,
        advisorTitl1: null,
        advisorMajor1: null,
        advisorNumber1: null,
        advisorName2: null,
        advisorTitl2: null,
        advisorMajor2: null,
        advisorNumber2: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null,
        signingStatus: null,
        cooperativeObject: null,
        resultYear: null,
        sixthName: null,
        sixthGrade: null,
        sixthMajor: null,
        sixthNumber: null,
        sixthCollege: null,
        sixthPhone: null,
        sixthIdnumber: null,
        seventhName: null,
        seventhGrade: null,
        seventhMajor: null,
        seventhNumber: null,
        seventhCollege: null,
        seventhPhone: null,
        seventhIdnumber: null,
        eighthName: null,
        eighthGrade: null,
        eighthMajor: null,
        eighthNumber: null,
        eighthCollege: null,
        eighthPhone: null,
        eighthIdnumber: null,
        ninthName: null,
        ninthGrade: null,
        ninthMajor: null,
        ninthNumber: null,
        ninthCollege: null,
        ninthPhone: null,
        ninthIdnumber: null,

      },
      user: '',
      // 以下websocket
      wsIsRun: false,
      // 定义ws对象
      webSocket: null,
      // ws连接次数
      wsNumber: 0,
      // ws请求链接（类似于ws后台地址）
      ws: '',
      // ws定时器
      wsTimer: null,
      // 以上websocket
      unreadMsgNums: 0,
      unreadMsgNumsShow: '',
      hasConnected: false,
    };
  },
  created() {
    this.wsIsRun = true
    this.wsNumber = 1
    this.wsInit();
    this.getList();
    const userId = this.$route.query.userId;
    if (userId) {
      // 获取表详细信息
        getView(userId).then(res => {
          this.form=res.data
          console.log(this.form+"111")
    });
    }
  },
  methods: {
    /** 查询分析报告列表 */
    getList() {
        let a =  this.$route.query.userId;
        listAchievement2(a).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加分析报告";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
          } else {
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除分析报告编号为"' + ids + '"的数据项？').then(function() {
        return delAnalysis(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/analysis/export', {
        ...this.queryParams
      }, `analysis_${new Date().getTime()}.xlsx`)
    },
    /**
     * 初始化ws
     */
    wsInit() {
      // console.log("userName: " + this.$store.state.user.ipp)
      console.log("user: " + this.$store.state.constip.ipp)
      const wsuri = 'ws://' + '10.100.37.207' + ':8080/library/wsService/' + this.$store.state.user.name
      this.ws = wsuri
      if (!this.wsIsRun)
        return
      // 销毁ws
      this.wsDestroy()
      // 初始化ws
      this.webSocket = new WebSocket(this.ws)
      // ws连接建立时触发
      this.webSocket.addEventListener('open', this.wsOpenHanler)
      // ws服务端给客户端推送消息
      this.webSocket.addEventListener('message', this.wsMessageHanler)
      // ws通信发生错误时触发
      this.webSocket.addEventListener('error', this.wsErrorHanler)
      // ws关闭时触发
      this.webSocket.addEventListener('close', this.wsCloseHanler)

      clearInterval(this.wsTimer);
    },
    subSend(userId) {

      //获取msg的value
      // var msg = document.getElementById("msg").value;

      this.webSocket.send(userId);

      // ws服务端给客户端推送消息

      // document.getElementById("msg").value="";
    },


    wsOpenHanler(event) {
      console.log('ws建立连接成功')
    },
    wsMessageHanler(e) {
      console.log('wsMessageHanler')
      console.log(e)
      //Cookies.set('unreadNums', '6')

      this.openMsg(e)
      //const redata = JSON.parse(e.data)
      //console.log(redata)

    },
    /**
     * ws通信发生错误
     */
    wsErrorHanler(event) {
      console.log(event, '通信发生错误')
      console.log("第" + this.wsNumber + "次断线重连(5次未连接将自动断开)")
      this.wsNumber++
      if (this.wsNumber < 6) this.wsInit();
      //this.wsInit()
    },
    /**
     * ws关闭
     */
    wsCloseHanler(event) {
      console.log(event, 'ws关闭')
      console.log("websocket连接超时，已自动断开")
      //this.wsInit()
    },
    /**
     * 销毁ws
     */
    wsDestroy() {
      console.log("hello world")
      if (this.webSocket !== null) {
        this.webSocket.removeEventListener('open', this.wsOpenHanler)
        this.webSocket.removeEventListener('message', this.wsMessageHanler)
        this.webSocket.removeEventListener('error', this.wsErrorHanler)
        this.webSocket.removeEventListener('close', this.wsCloseHanler)
        this.webSocket.close()
        this.webSocket = null
        clearInterval(this.wsTimer)
        console.log("zoul111")
      } else {
        console.log("zoul")
      }
    },
    /**
     * 弹窗
     */
    openMsg(e) {
      const h = this.$createElement;
      if (e.data) {
        console.log(e.data)
        if(e.data === this.$route.query.userId){
          this.$router.push({path: "/dashuju"});
        }
        /*var dv = document.getElementById("dv");
        dv.innerHTML += e.data + " ";*/


        // var data = JSON.parse(e.data)
        // var route = this.$router;
        // var msgType = data.msgType;
        /*if (msgType == "push") {
          // 如果是推送的是一条消息
          this.unreadMsgNums++;
          if (this.unreadMsgNums > 99) {
            this.unreadMsgNumsShow = "99+";
          } else {
            this.unreadMsgNumsShow = String(this.unreadMsgNums);
          }

          this.$notify.info({
            title: data.msgTitle,
            message: data.msgContent,
            onClick() {
              console.log(route)
              route.push({path: "/library/yyg/msg/list"});
            }
          });
        } else if (msgType == "unread") {
          // 如果推送的是未读消息数
          //Cookies.set('unreadNums', data.unreadNums);
          this.unreadMsgNums = Number(data.unreadNums);
          if (this.unreadMsgNums > 0) {
            this.unreadMsgNumsShow = String(this.unreadMsgNums);
            if (this.unreadMsgNums > 99) {
              this.unreadMsgNumsShow = "99+";
            }
            this.$notify.info({
              title: "消息提醒",
              //message: data.msgContent,
              message: "您当前有" + this.unreadMsgNumsShow + "条未读消息，点击此处查看",
              onClick() {
                console.log(route)
                route.push({path: "/library/yyg/msg/list"});
              }
            });
          }
        } else if (msgType == "read") {
          // 如果推送的是用户已读消息
          this.unreadMsgNums--;
          if (this.unreadMsgNums > 0 && this.unreadMsgNums <= 99) {
            this.unreadMsgNumsShow = String(this.unreadMsgNums);
          } else if (this.unreadMsgNums <= 0) {
            this.unreadMsgNumsShow = '';
          }
        }
*/
      }
    },
  }
};
</script>
